#include <bits/stdc++.h>

using namespace std;

const int N=5e5+10;

int k;
int a[N],b[N];

int main()
{
	cin>>k;
	string s;cin>>s;
	int len=s.size();
	s=" "+s;
	char c1,c2;cin>>c1>>c2;
	
	int len1=0,len2=0;
	for(int i=1;i<=len;i++)
	{
		if(s[i]==c1) a[++len1]=i;
		if(s[i]==c2) b[++len2]=i;
	}
	long long ret=0;
	for(int i=1;i<=len1;i++)
	{
		int left=1,right=len2;
		while(left<right)
		{
			int mid=left+(right-left)/2;
			if(b[mid]-a[i]+1>=k) right=mid;
			else left=mid+1;
		}
		if(b[left]-a[i]+1>=k) ret+=(len2-left+1);
	}
	cout<<ret<<endl;
	return 0;
}
